package com.zhentao.controller;

import com.github.pagehelper.PageInfo;
import com.zhentao.bean.QueryParam;
import com.zhentao.bean.Result;
import com.zhentao.pojo.Classes;
import com.zhentao.pojo.Student;
import com.zhentao.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("student")
public class StudentController {
    @Autowired
    private StudentService studentService;
    //RequestParam 用来设置默认值，名称不一致
    @RequestMapping("list")
    @ResponseBody
    public Result list(@RequestParam(defaultValue = "2",value = "currentPage1") int currentPage, @RequestParam(defaultValue = "2") int pageSize, QueryParam queryParam){
        //调用业务层查数据---实现分页
        PageInfo<Student> pageInfo=studentService.findPage(currentPage,pageSize,queryParam);
        //向前端送分页数据
        return Result.Ok("查询分页列表成功",pageInfo);
    }
    //添加操作
    @RequestMapping("add")
    @ResponseBody
    public Result add(Student student, Classes classes){
        System.out.println(student);
        System.out.println(classes);
        studentService.insert(student,classes);
        return Result.Ok("添加成功");
    }
}
